package com.chukun.spring.beans.defination;


import com.chunkun.ioc.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author chukun
 *  实例化bean的方式
 */
public class BeanInstantiationDemo {

    public static void main(String[] args) {

        BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-instantiation-context.xml");

        // 静态方式创建对象
        User staticUser = beanFactory.getBean("user-by-static-method", User.class);
        System.out.println(staticUser);

        // 静态方式创建对象
        User instanceMethodUser = beanFactory.getBean("user-by-instant-method", User.class);
        System.out.println(instanceMethodUser);

        // factoryBean的方式实现
        User factoryBeanUser = beanFactory.getBean("user-factory-bean", User.class);
        System.out.println(factoryBeanUser);

    }
}
